/*
* 文 件 名:  UserServiceImpl.java
* 版    权:  Tydic Technologies Co., Ltd. Copyright 1993-2012,  All rights reserved
* 描    述:  用户信息服务实现
* 修 改 人:  agan
* 修改时间:  2012-9-5
* 跟踪单号:  <跟踪单号>
* 修改单号:  <修改单号>
* 修改内容:  <修改内容>
*/

package com.tydic.simple.service.user.impl;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.tydic.simple.dao.user.IUserDAO;
import com.tydic.simple.model.user.User;
import com.tydic.simple.service.exception.UserException;
import com.tydic.simple.service.user.IUserService;

/**
* 用户信息服务实现
* <功能详细描述>
* 
* @author  agan
* @version  [1.0, 2012-9-5]
* @since  [权限管理/1.0]
*/
public class UserServiceImpl implements IUserService {
    
    private static final Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);
    
    private IUserDAO userDao;
    
    /** {@inheritDoc} */
    @Override
    public Long saveUser(User user)
        throws UserException {
        if (user == null) {
            logger.error("userinfo is empty.");
            throw new UserException("user info is not complete");
        }
        if (StringUtils.isBlank(user.getLoginId())) {
            logger.error("user loginId is empty. user:(" + user.toString() + ")");
            throw new UserException("user loginId is emplty");
        }
        if (StringUtils.isBlank(user.getPassword())) {
            logger.error("user password is empty. user:(" + user.toString() + ")");
            throw new UserException("user password is empty");
        }
        userDao.findUserByLoginId(user.getLoginId());
        return userDao.saveUser(user);
    }
    
    /** {@inheritDoc} */
    @Override
    public int deleteUserByLoginId(String loginId)
        throws UserException {
        
        if (StringUtils.isBlank(loginId)) {
            logger.error("user loginId is empty");
            throw new UserException("loginId is empty!");
        }
        return userDao.deleteUserByLoginId(loginId);
        
    }
    
    /** {@inheritDoc} */
    @Override
    public User findUserByLoginId(String loginId)
        throws UserException {
        
        if (StringUtils.isBlank(loginId)) {
            logger.error("user loginId is empty");
            throw new UserException("loginId is empty!");
        }
        return userDao.findUserByLoginId(loginId);
    }
    
    public IUserDAO getUserDao() {
        return userDao;
    }
    
    public void setUserDao(IUserDAO userDao) {
        this.userDao = userDao;
    }

     /** {@inheritDoc} */
    @Override
    public User findUser(String username, String password)
        throws UserException {
        return null;
    }
    
}
